package servlet;

import java.io.IOException;
import java.sql.Time;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.ejb.EJB;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import managers.manEvent;

/**
 * Servlet implementation class SaddEvent
 */
public class SaddEvent extends HttpServlet {
	private static final long serialVersionUID = 1L;
	@EJB
	manEvent manE;
    /**
     * @see HttpServlet#HttpServlet()
     */
    public SaddEvent() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		response.setContentType("text/html");
		
		

		String name = (String)request.getParameter("name");
		String des = (String)request.getParameter("des");
		String place = (String)request.getParameter("place");
		String hour = (String)request.getParameter("hour");
		String date = (String)request.getParameter("date");
		String nb = (String)request.getParameter("nb");
		String promoterId = (String)request.getParameter("idPromo");
		

		String idCate = (String)request.getParameter("idCate");
		//pour tester	
		SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");

			Date tDate;
			boolean v;
			try {
				
				tDate = (Date)sdf.parse(date);
				System.out.println("thisDate"+tDate);
				
				v = manE.addEvent(name, des, place,hour , tDate, Integer.parseInt(nb), Integer.parseInt(idCate),promoterId);
				
				String message="Vous n'avez pas reussi a creer l'event:"+name;
				if (v==true){
					message="Vous avez reussi a creer l'event: : "+name;
				}
				request.setAttribute("message", message);

				request.getRequestDispatcher("/addEvent.jsp").forward(request, response);
			} catch (ParseException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request,response);
	}

}
